package com.translate.web.service.impl;

import com.translate.web.constant.RedisConstant;
import com.translate.web.dao.PayTypeMapper;
import com.translate.entity.PayType;
import com.translate.vo.contract.IPayTypeVO;
import com.translate.web.service.IPayTypeService;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class PayTypeServiceImpl extends BaseTranslateServiceImpl<PayType> implements IPayTypeService {
	
	@Resource
	public void setRedisTemplate(RedisTemplate<String, ? extends Object> redisTemplate) {
		this.redisTemplate = redisTemplate;
	}

	public PayTypeServiceImpl(PayTypeMapper mapper) {
		super(mapper);
	}

	protected void insertPropteris(PayType data) {
		long time = System.currentTimeMillis() / 1000;
		data.setCreateTime(time);
		data.setUpdateTime(time);
	}

	protected void updatePropteris(PayType data) {
		data.setUpdateTime(System.currentTimeMillis() / 1000);
	}

	
	
	@Override
	protected int getId(PayType data) {
		// TODO Auto-generated method stub
		return data.getId();
	}

	protected Class<PayType> getEntityClass() {
		return PayType.class;
	}

	@Override
	public <VO extends IPayTypeVO> List<VO> getListFromCache(Class<VO> target) {
		return this.entityConvertToVo(this.listToHash(RedisConstant.PAY_TYPE, 10000), target);
	}

	@Override
	public <VO extends IPayTypeVO> VO getPayItemFromCache(int id, Class<VO> target) {
		return null;
	}

	@Override
	public PayType getPayItemFromCache(int id) {
		HashOperations<String, String, PayType> hashOperations = redisTemplate.opsForHash();
		
		if (0 == hashOperations.size(RedisConstant.PAY_TYPE)) {
			this.dataToHash(RedisConstant.PAY_TYPE, 10000, hashOperations);
		}
		
		return hashOperations.get(RedisConstant.PAY_TYPE, id+ "");
	}
	
}